package com.hethongviet.vending.helper.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hethongviet.vending.R;
import com.hethongviet.vending.Utils;

public class DialogEditDomainName extends Dialog
{
	private EditText _EditTextDomain = null;

	private TextView _TextViewWrongFormat = null;

	private Button _ButtonAccept = null;
	private Button _ButtonCancel = null;

	@SuppressWarnings("unused")
	private Activity _activity = null;

	@Override
	public void show()
	{
		Utils.debug("show dialog edit domain!!!!!show");
		super.show();
	}

	public DialogEditDomainName(Activity activity, String domainName)
	{

		super(activity);
		Utils.debug("show dialog edit domain!!!!!DialogEditDomainName");
		_activity = activity;

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_edit_domain_name);

		_TextViewWrongFormat = (TextView) findViewById(R.id.config_edit_wrong_format);

		_EditTextDomain = (EditText) findViewById(R.id.config_edit_domain_name);
		_EditTextDomain.setText(domainName);

		_ButtonAccept = (Button) findViewById(R.id.button_config_edit_accept);
		_ButtonCancel = (Button) findViewById(R.id.button_config_edit_cancel);

		_ButtonAccept.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0)
			{

				String textDomain = _EditTextDomain.getText().toString();
				if (textDomain == null || textDomain.equals(""))
				{
					_TextViewWrongFormat.setVisibility(View.VISIBLE);
				}
				else
				{
					_TextViewWrongFormat.setVisibility(View.GONE);

					//((ConfigMachineActivity) _activity).updateDomainName(textDomain);

					hide();
					// dismiss();
					// cancel();
				}
			}
		});

		_ButtonCancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0)
			{
				// ((ConfigMachineActivity) _activity).updateDomainName(null);
				// hide();
				// dismiss();
				// cancel();
			}
		});
	}

//	@Override
//	public boolean dispatchKeyEvent(KeyEvent event)
//	{
//		return AppMain.getInstance().disableAllKey(event);
//		// return super.dispatchKeyEvent(event);
//	}
}
